﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiskInventory
{
    public partial class PrintDialog : Form
    {
        /// <summary>
        /// Handles printing
        /// </summary>
        public PrintDialog()
        {
            InitializeComponent();
            UpdatePrintPreview();
        }

        private void buttonPageSetup_Click(object sender, EventArgs e)
        {
            this.listViewPrinter1.PageSetup();
            this.UpdatePrintPreview();
        }

        private void buttonPreview_Click(object sender, EventArgs e)
        {
            this.listViewPrinter1.PrintPreview();
        }

        private void buttonPrint_Click(object sender, EventArgs e)
        {
            this.listViewPrinter1.PrintWithDialog();
        }

        private void radioButtonAuto_CheckedChanged(object sender, EventArgs e)
        {
            this.printPreviewControl1.Zoom = 1.0;
            this.printPreviewControl1.AutoZoom = true;
        }

        private void radioButton200_CheckedChanged(object sender, EventArgs e)
        {
            this.printPreviewControl1.Zoom = 2.0;
        }

        private void radioButton100_CheckedChanged(object sender, EventArgs e)
        {
            this.printPreviewControl1.Zoom = 1.0;
        }

        private void radioButton50_CheckedChanged(object sender, EventArgs e)
        {
            this.printPreviewControl1.Zoom = 0.5;
        }

        private void numericUpDownPages_ValueChanged(object sender, EventArgs e)
        {
            int pages = (int)this.numericUpDownPages.Value;

            switch (pages)
            {
                case 1:
                case 2:
                case 3:
                    this.printPreviewControl1.Rows = 1;
                    this.printPreviewControl1.Columns = pages;
                    break;
                default:
                    this.printPreviewControl1.Rows = 2;
                    this.printPreviewControl1.Columns = ((pages - 1) / 2) + 1;
                    break;
            }
        }
        private void UpdatePrintPreview()
        {
            this.listViewPrinter1.IsShrinkToFit = true;
            this.listViewPrinter1.IsListHeaderOnEachPage = true;

            this.listViewPrinter1.CellFormat = null;
            this.listViewPrinter1.ListFont = new Font("Tahoma", 9);

            this.listViewPrinter1.HeaderFormat = BrightIdeasSoftware.BlockFormat.Header();
            this.listViewPrinter1.HeaderFormat.TextBrush = Brushes.Black;
            this.listViewPrinter1.HeaderFormat.BackgroundBrush = null;
            this.listViewPrinter1.HeaderFormat.SetBorderPen(BrightIdeasSoftware.Sides.Bottom, 
                new Pen(Color.Black, 0.5f));

            this.listViewPrinter1.FooterFormat = BrightIdeasSoftware.BlockFormat.Footer();
            this.listViewPrinter1.GroupHeaderFormat = BrightIdeasSoftware.BlockFormat.GroupHeader();
            this.listViewPrinter1.GroupHeaderFormat.SetBorder(BrightIdeasSoftware.Sides.Bottom, 2, 
                new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, 1, 1), Color.Gray, 
                    Color.White, System.Drawing.Drawing2D.LinearGradientMode.Horizontal));

            this.listViewPrinter1.ListHeaderFormat = BrightIdeasSoftware.BlockFormat.ListHeader();
            this.listViewPrinter1.ListHeaderFormat.BackgroundBrush = null;

            this.listViewPrinter1.WatermarkFont = null;
            this.listViewPrinter1.WatermarkColor = Color.Empty;


            this.printPreviewControl1.InvalidatePreview();
        }
        /// <summary>
        /// Shows the priunt dialog with the current tree view
        /// </summary>
        /// <param name="aOLV"></param>
        /// <returns></returns>
        public DialogResult ShowDialog(BrightIdeasSoftware.ObjectListView aOLV)
        {
            this.listViewPrinter1.ListView = aOLV;
            return this.ShowDialog();
        }
    }
}
